#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import time

from faker import Faker

from application.models import db, User
from manage import app
import unittest

fake = Faker('zh_CN')
fake_en = Faker()


class FlaskTest(unittest.TestCase):
    """通过测试脚本初始化数据库"""

    def setUp(self):
        app.app_context().push()
        app.testing = True  # 开启测试模式
        self.client = app.test_client()

    def test_get(self):
        """测试函数，必须以test开头"""
        resp = self.client.get("/")

    def test_init_db(self):
        """测试函数，必须以test开头"""
        c = User()
        c.id = int(time.time() * 100000000)
        c.name = fake.word()
        c.email = fake_en.email()
        c.phone = random.randint(13900000000, 13999999999)
        c.password = '123456'
        db.session.add(c)
        db.session.commit()


if __name__ == '__main__':
    # 启动所有测试
    unittest.main()
